#define FUR_HELPERS_INCLUDED

#include "UnityCG.cginc"

struct v2f {
  V2F_POS_FOG;
  float3 viewDir : TEXCOORD1;
  float3 color : COLOR;
  float4 uv : TEXCOORD0;
  
}; 

//uniform float _Dist;
uniform float _Alpha;
uniform float _Scale;

sampler2D _MainTex : register(s0);

v2f VertexProgram (appdata_base v)
{
	v2f o;
	PositionFog( v.vertex, o.pos, o.fog );
	o.viewDir = ObjSpaceViewDir(0);
	
	o.uv = v.vertex - float4(o.viewDir,0)*_Dist;
	o.color = o.uv;
	return o;
}

v2f VertexProgram3 (appdata_base v)
{
	v2f o;
	PositionFog( v.vertex, o.pos, o.fog );
	o.viewDir = ObjSpaceViewDir(v.vertex);
	//o.color = dot(o.viewDir.xy, 1);//_Alpha;
	o.color = clamp(abs(dot(normalize(float3(v.vertex.x, 0, v.vertex.z)),normalize(float3(o.viewDir.x, 0, o.viewDir.z)))),0,1)*_Alpha;
	//o.uv = v.vertex - float4(o.viewDir,0)*_Dist;
	return o;
}

half4 fragStep(float2 uv, float2 dir, float dist)
{
	return tex2D(_MainTex, uv.xy-dir*dist);
}

half4 frag(v2f i) : COLOR {
	//i.normal = normalize(i.normal);
	//return tex2D(_MainTex, uv);
	
	float2 uv = i.uv.xy*_Scale;
	float2 vDir = i.viewDir.xy-uv;
	uv+=.5;
	half4 ret = fragStep(uv, vDir, 0);
	ret += fragStep(uv, vDir, 0.1);
	ret += fragStep(uv, vDir, 0.2);
	ret += fragStep(uv, vDir, 0.3);
	ret += fragStep(uv, vDir, 0.4);
	ret += fragStep(uv, vDir, 0.5);
	ret += fragStep(uv, vDir, 0.6);
	ret += fragStep(uv, vDir, 0.7);
	ret += fragStep(uv, vDir, 0.8);
	ret += fragStep(uv, vDir, 0.9);
	ret += fragStep(uv, vDir, 1.0);
	
	return ret*_Alpha/_Power;
}

half4 fragI(v2f i) : COLOR {
	//i.normal = normalize(i.normal);
	//return tex2D(_MainTex, uv);
	
	float2 uv =  i.viewDir.xy;
	float2 vDir = uv-i.uv.xy*_Scale;
	uv+=.5;
	half4 ret = fragStep(uv, vDir, 0);
	ret += fragStep(uv, vDir, 0.1);
	ret += fragStep(uv, vDir, 0.2);
	ret += fragStep(uv, vDir, 0.3);
	ret += fragStep(uv, vDir, 0.4);
	ret += fragStep(uv, vDir, 0.5);
	ret += fragStep(uv, vDir, 0.6);
	ret += fragStep(uv, vDir, 0.7);
	ret += fragStep(uv, vDir, 0.8);
	ret += fragStep(uv, vDir, 0.9);
	ret += fragStep(uv, vDir, 1.0);

	return ret*_Alpha/_Power;
}
#endif